import Vue from 'vue'
import Router from 'vue-router'
import UpdataHotMovieInfor from '@/views/HotMovies/UpdataHotMovieInfor'
import HotIndext from '@/views/HotMovies/index'
import AddHotMovies from '@/views/HotMovies/AddHotMovies'
import Updatatimetable from '@/views/timetable/Updatatimetable'
import Addtimetable from '@/views/timetable/addtimetable'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '主页', icon: 'dashboard' }
    }]
  },
  {
    path: '/User',
    component: Layout,
    meta: {
      title: '用户管理',
      icon: 'user'
    },
    children: [
      {
        path: '/user',
        name: '用户管理',
        component: () => import('@/views/User/index'),
        meta: { title: '用户管理' }
      }
    ]
  },
  {
    path: '/next',
    component: Layout,
    // redirect: '/example/table',
    name: 'Table',
    meta: { title: '即将上映电影', icon: 'example' },
    children: [
      {
        path: '/nextfilm',
        name: 'nextfilm',
        component: () => import('@/views/nextfilmmanager/NextFilm'),
        meta: { title: '电影列表', icon: 'table' }
      },
      {
        path: 'addnextfilm',
        name: 'addnextfilm',
        component: () => import('@/views/nextfilmmanager/index'),
        meta: { title: '新增电影', icon: 'form' }
      },
      {
        path: 'changefilm',
        name: 'changefilm',
        hidden: true,
        component: () => import('@/views/nextfilmmanager/Change'),
        meta: { title: '修改电影', icon: 'form' }
      }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/HotIndext',
    name: 'Example',
    meta: { title: '热映电影', icon: 'example' },
    children: [
      { // 热映电影管理页
        path: 'table',
        name: 'HotIndext',
        component: HotIndext,
        meta: { title: '热映电影管理', icon: 'table' }
      },
      { // 修改热映电影信息页
        path: '/UpdataHotMovieInfor',
        component: UpdataHotMovieInfor,
        name: 'UpdataHotMovieInfor'
      },
      { // 添加热映电影
        path: '/AddHotMovies',
        component: AddHotMovies,
        name: 'AddHotMovies'
      }
    ]
  },
  {
    path: '/timeTable',
    component: Layout,
    meta: {
      title: '放映时间管理',
      icon: 'table'
    },
    children: [
      {
        path: '/timetable',
        name: '放映时间管理',
        component: () => import('@/views/timetable/index'),
        meta: { title: '放映时间管理' }
      },
      { // 修改放映信息页
        path: '/updatatimetable',
        component: Updatatimetable,
        name: 'Updatatimetable'
      },
      { // 添加放映信息
        path: '/addtimetable',
        component: Addtimetable,
        name: 'addtimetable'
      }
    ]
  },
  {
    path: '/Order',
    component: Layout,
    meta: {
      title: '订单管理',
      icon: 'table'
    },
    children: [
      {
        path: '/order',
        name: '订单管理',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理' }
      }
    ]
  },
  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },
  //
  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },
  //
  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
